int AlphaBetaPruning(int level, int alpha, int beta)
{
if (level == limit)
{
return evaluate(aiPlayer) - evaluate(userPlayer);
}
if (level % 2 == 0)
{
int max = -1000000;
int find = 0;
for (int i = 0; i < edgeCount; i++)
{
for (int j = 0; j < edgeCount; j++)
{
if (board[i, j] == 0)
{
board[i, j] = aiPlayer;
int e = AlphaBetaPruning(level + 1, alpha, beta);
board[i, j] = 0;
if (max < e)
{
max = e;
if (level == 0)
{
targetX = i;
targetY = j;
}
}
if (alpha < max)
{
alpha = max;
if (alpha >= beta) find = 1;
}
}
if (find == 1) break;
}
if (find == 1) break;
}
return max;
}
else
{
int min = 1000000;
int find = 0;
for (int i = 0; i < edgeCount; i++)
{
for (int j = 0; j < edgeCount; j++)
{
if (board[i, j] == 0)
{
board[i, j] = userPlayer;
int e = AlphaBetaPruning(level + 1, alpha, beta);
board[i, j] = 0;
if (min > e) min = e;
if (beta > min)
{
beta = min;
if (alpha >= beta) find = 1;
}
}
if (find == 1) break;
}
if (find == 1) break;
}
return min;
}
}